import React from 'react';
import { WeaSwitch } from 'comsMobx';
import { WeaFormItem } from 'ecCom';

/**
 * 公文类  公用查询面板
 */
class SearchComponent extends React.Component {
  onChange(data) {
    const { searchStore } = this.props;

    searchStore.isSearched();
    if (data.officalType) {
      searchStore.form.updateFields({
        docnode: {
          value: '',
        },
      });
    }
    if (searchStore.searchType == 2) {
      if (data.officalType) {
        if (data.officalType.value == '1') {
          searchStore.setSearchType_display_fw('block');
          searchStore.setSearchType_display_sw('none');
          searchStore.setSearchType_display_qb('none');
        } else if (data.officaltype.value == '2') {
          searchStore.setSearchType_display_fw('none');
          searchStore.setSearchType_display_sw('block');
          searchStore.setSearchType_display_qb('none');
        } else if (data.officaltype.value == '3') {
          searchStore.setSearchType_display_fw('none');
          searchStore.setSearchType_display_sw('none');
          searchStore.setSearchType_display_qb('block');
        } else {
          searchStore.setSearchType_display_fw('none');
          searchStore.setSearchType_display_sw('none');
          searchStore.setSearchType_display_qb('none');
        }
      }
    }
  }

  onBlur() {

  }

  render() {
    const { searchStore, listStore } = this.props;
    const conditioninfo = searchStore.searchCondition.condition || searchStore.searchCondition.conditions;
    const { form } = searchStore;
    const { isFormInit } = form;
    let group = [];

    isFormInit && conditioninfo.map((c) => {
      let items = [];
      c.items.map((field) => {
        if (searchStore.searchType == 2 && field.label == '发文环节') {
          items.push(
            <div style={{ display: searchStore.searchType_display_fw }}>
              <WeaFormItem ecId={`${this && this.props && this.props.ecId || ''}_WeaFormItem@jsd387@${field.domkey[0]}`} label={`${field.label}`} labelCol={{ span: 4 }} error={form.getError(field)} tipPosition="bottom" wrapperCol={{ span: 20 }} >
                <WeaSwitch ecId={`${this && this.props && this.props.ecId || ''}_WeaSwitch@lnrgfo@${field.domkey[0]}`} fieldConfig={field} form={form} onChange={this.onChange.bind(this)} onBlur={this.onBlur.bind(this)} onEnterSearch={() => listStore.doSearch()} />
              </WeaFormItem>
            </div>);
        } else if (searchStore.searchType == 2 && field.label == '收文环节') {
          items.push(
            <div style={{ display: searchStore.searchType_display_sw }}>
              <WeaFormItem ecId={`${this && this.props && this.props.ecId || ''}_WeaFormItem@1z7ri3@${field.domkey[0]}`} label={`${field.label}`} labelCol={{ span: 4 }} error={form.getError(field)} tipPosition="bottom" wrapperCol={{ span: 20 }} >
                <WeaSwitch ecId={`${this && this.props && this.props.ecId || ''}_WeaSwitch@owalhl@${field.domkey[0]}`} fieldConfig={field} form={form} onChange={this.onChange.bind(this)} onBlur={this.onBlur.bind(this)} onEnterSearch={() => listStore.doSearch()} />
              </WeaFormItem>
            </div>);
        } else if (searchStore.searchType == 2 && field.label == '签报环节') {
          items.push(
            <div style={{ display: searchStore.searchType_display_qb }}>
              <WeaFormItem ecId={`${this && this.props && this.props.ecId || ''}_WeaFormItem@69e868@${field.domkey[0]}`} label={`${field.label}`} labelCol={{ span: 4 }} error={form.getError(field)} tipPosition="bottom" wrapperCol={{ span: 20 }} >
                <WeaSwitch ecId={`${this && this.props && this.props.ecId || ''}_WeaSwitch@x7dbqw@${field.domkey[0]}`} fieldConfig={field} form={form} onChange={this.onChange.bind(this)} onBlur={this.onBlur.bind(this)} onEnterSearch={() => listStore.doSearch()} />
              </WeaFormItem>
            </div>);
        } else {
          items.push(<WeaFormItem ecId={`${this && this.props && this.props.ecId || ''}_WeaFormItem@oznkn4@${field.domkey[0]}`}
            label={`${field.label}`}
            labelCol={{ span: 4 }}
            error={form.getError(field)}
            tipPosition="bottom"
            wrapperCol={{ span: 20 }}
          >
            <WeaSwitch ecId={`${this && this.props && this.props.ecId || ''}_WeaSwitch@hhv043@${field.domkey[0]}`}
              fieldConfig={field}
              form={form}
              onChange={this.onChange.bind(this)}
              onBlur={this.onBlur.bind(this)}
              onEnterSearch={() => listStore.doSearch()}
            />
          </WeaFormItem>);
        }


        group = items;
      });
    });
    return (<div className="wea-odoc-advanced-searchsAd">{group}</div>);
  }
}


export default SearchComponent;
